www.gusucode.com > DB-Libray 操作SQLServer编程的VC++ 一例-源码程序 > DB-Libray 操作SQLServer编程的VC++ 一例-源码程序\code\PhManage\PhysicRateDlg.cpp
// PhysicRateDlg.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "PhysicM.h" #include "PhysicRateDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPhysicRateDlg dialog CPhysicRateDlg::CPhysicRateDlg(CWnd* pParent /*=NULL*/) : CDialog(CPhysicRateDlg::IDD, pParent) { //{{AFX_DATA_INIT(CPhysicRateDlg) m_demo = _T(""); m_rate = 0.0; m_doctor_rate = 0.0; //}}AFX_DATA_INIT } void CPhysicRateDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPhysicRateDlg) DDX_Control(pDX, IDC_PROVIDER_COMB, m_ProviderComb); DDX_Control(pDX, IDC_PHYSICRATE_LIST, m_List); DDX_Control(pDX, IDC_PHYSIC_COMB, m_PhysicComb); DDX_Text(pDX, IDC_DEMO_EDIT, m_demo); DDX_Text(pDX, IDC_RATE_EDIT, m_rate); DDX_Text(pDX, IDC_DRATE_EDIT, m_doctor_rate); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPhysicRateDlg, CDialog) //{{AFX_MSG_MAP(CPhysicRateDlg) ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton) ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPhysicRateDlg message handlers void CPhysicRateDlg::OnOK() { // TODO: Add extra validation here // CDialog::OnOK(); } BOOL CPhysicRateDlg::OnInitDialog() { CDialog::OnInitDialog(); m_List.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); char *head[]={"序 号","药品名称","供应商名称","个人费用","临床费用","ID","备注"}; int i; for (i=0;i<7;i++) m_List.InsertColumn(i,head[i],(i==3 || i==4)? LVCFMT_RIGHT : LVCFMT_LEFT,(i==2) ? 180 : 90,i); ImageList=new CImageList(); ImageList->Create(16,16,TRUE | ILC_COLOR32,2,0); ImageList->Add(AfxGetApp()->LoadIcon(IDI_ICONUSER)); ImageList->Add(AfxGetApp()->LoadIcon(IDR_MENUVIEW_TMPL)); m_List.SetImageList(ImageList,LVSIL_SMALL);// LVSIL_NORMAL); Init(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } BOOL CPhysicRateDlg::DestroyWindow() { if (ImageList) delete ImageList; return CDialog::DestroyWindow(); } void CPhysicRateDlg::Init() { DBLibrary DB(((CPhysicMApp *)AfxGetApp())->DBSession); try{ DB.Open("SELECT physic_id pid,physic_name pn from physic order by physic_id"); int id=0; char pname[40],tmp[50]; memset(pname,0,40); while(!DB.isEof()) { id=DB.GetValue("pid"); DB.GetValue("pn",pname); sprintf(tmp,"[%03d]%s",id,pname); m_PhysicComb.AddString((LPCTSTR)tmp); DB.Next(); } // DB.Open("SELECT Provider_id pid,Provider_name pn from Provider order by Provider_id"); id=0; memset(pname,0,40); memset(tmp,0,50); while(!DB.isEof()) { id=DB.GetValue("pid"); DB.GetValue("pn",pname); sprintf(tmp,"[%03d]%s",id,pname); m_ProviderComb.AddString((LPCTSTR)tmp); DB.Next(); } DB.Open("select a.rate_id rid," "b.physic_name pn," "c.provider_name rn," "a.rate ra," "a.doctor_rate dra," "a.demo dm " " from physic_rate a,physic b,provider c " " where a.physic_id=b.physic_id and a.provider_id=c.provider_id " " order by a.rate_id"); int no=0; double rate=0.00; while(!DB.isEof()) { sprintf(tmp,"%03d",no+1); m_List.InsertItem(no,tmp,0); memset(tmp,0,50); DB.GetValue("pn",tmp); m_List.SetItemText(no,1,(LPCTSTR)tmp); memset(tmp,0,50); DB.GetValue("rn",tmp); m_List.SetItemText(no,2,(LPCTSTR)tmp); DB.GetValue("ra",&rate); sprintf(tmp,"%.2f",rate); m_List.SetItemText(no,3,(LPCTSTR)tmp); rate=0.00; DB.GetValue("dra",&rate); sprintf(tmp,"%.2f",rate); m_List.SetItemText(no,4,(LPCTSTR)tmp); id=DB.GetValue("rid"); sprintf(tmp,"%03d",id); m_List.SetItemText(no,5,(LPCTSTR)tmp); memset(tmp,0,50); DB.GetValue("dm",tmp); m_List.SetItemText(no,6,(LPCTSTR)tmp); no++; DB.Next(); } }catch (DBErr &err) { char *str; int code; err.GetLastErr(code,&str); ((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr("%s(%d)",str,code); } catch (...) { ((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr("unknow err(%d)",-1); } } void CPhysicRateDlg::AddInfo(CString m_pname,CString m_pr,double m_ra,double m_dra,CString m_dm) { DBLibrary DB(((CPhysicMApp *)AfxGetApp())->DBSession); int max_id=0; CString hp_id,pr_id; hp_id=m_pname.Mid(1,3); pr_id=m_pr.Mid(1,3); try{ DB.Open("select IDENT_CURRENT('physic_rate') did " " from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='physic_rate' "); double id=0; DB.GetValue("did",&id); max_id=(int)id+1; DB.ExecSQL("INSERT INTO Physic_Rate (Physic_id,provider_id,rate,doctor_rate,demo) " "VALUES(%s,%s,%.2f,%.2f,'%s')",hp_id,pr_id,m_ra,m_dra,m_dm); ((CPhysicMApp *)AfxGetApp())->pMainFrm->AddLog("新增药品费率:%s",m_pname); char no[4],tmp[20]; int icount=m_List.GetItemCount(); memset(no,0,4); sprintf(no,"%03d",icount+1); m_List.InsertItem(m_List.GetItemCount(),no,0); m_List.SetItemText(icount,1,(LPCTSTR)m_pname); m_List.SetItemText(icount,2,(LPCTSTR)m_pr); sprintf(tmp,"%.2f",m_ra); m_List.SetItemText(icount,3,(LPCTSTR)tmp); sprintf(tmp,"%.2f",m_dra); m_List.SetItemText(icount,4,(LPCTSTR)tmp); sprintf(no,"%03d",max_id); m_List.SetItemText(icount,5,(LPCTSTR)no); m_List.SetItemText(icount,6,(LPCTSTR)m_dm); } catch (DBErr &err) { char *str; int code; err.GetLastErr(code,&str); ((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr("%s(%d)",str,code); } catch(...) { ((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr("unknow err(%d)",-1); } } void CPhysicRateDlg::OnAddButton() { UpdateData(); CString hp,pr; m_PhysicComb.GetWindowText(hp); m_ProviderComb.GetWindowText(pr); hp.TrimLeft(); hp.TrimRight(); pr.TrimLeft(); pr.TrimRight(); if(hp.IsEmpty()) { ((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr("药品不能为空,请选择"); return; } if(pr.IsEmpty()) { ((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr("供应商不能为空,请选择"); return; } if(m_rate<0.00 || m_rate>1000.00) { ((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr("个人费率太大或太小,请重输"); return; } if(m_doctor_rate<0.00 || m_doctor_rate>1000.00) { ((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr("医生费率太大或太小,请重输"); return; } AddInfo(hp,pr,m_rate,m_doctor_rate,m_demo); } void CPhysicRateDlg::OnDeleteButton() { ((CPhysicMApp *)AfxGetApp())->Delete("Physic_Rate","Rate_id",&m_List,5); }